#include "PHYCollisionObjects.h"
int PHYCollisionObj::_index = 0;
//PHYCollisionObj::PHYCollisionObj()
//{
//}
PHYCollisionObj::PHYCollisionObj(PHY_Shapes iShape, osg::Geode *iGeode, PHYVector &iLocation)
{
	PHYVector orig(0,0,0);
	_Object = new osg::PositionAttitudeTransform();
	setLocation(orig);
	setLocation(iLocation);
	_Object->addChild(iGeode);
	_index++;
	_thisIndex = _index;
	_Shape = iShape;
	_Location.setVector(iLocation);
}
PHYCollisionObj::PHYCollisionObj(PHY_Shapes iShape, osg::Node *ipNode, PHYVector &iLocation)
{
	PHYVector orig(0,0,0);
	ipNode->setNodeMask( 0x1 );
	_Object = new osg::PositionAttitudeTransform();
	setLocation(orig);
	setLocation(iLocation);
	_Object->addChild(ipNode);
	_index++;
	_thisIndex = _index;
	_Shape = iShape;
	_Location.setVector(iLocation);
}
PHYSphere::PHYSphere(osg::Geode *iGeode, double iRadius, PHYVector &iOrigin) 
:PHYCollisionObj(PHY_Sphere, iGeode, iOrigin)
{
	_Radius = iRadius;
}
void PHYCollisionObj::setLocation(PHYVector &iLoc)
{
	//osg::Vec3d vec1;
	osg::Vec3d vec(iLoc.getX(), iLoc.getY(), iLoc.getZ());
	_Location.setVector(iLoc);
	_Object->setPosition(vec);
	//vec1 = _Object->getPosition();
}

osg::PositionAttitudeTransform* PHYCollisionObj::getTransform()
{
	return _Object;
}

//osg::PositionAttitudeTransform* PHYBox::getTransform()
//{
//	return _Object;
//}

PHYVector PHYCollisionObj::getLocation() const
{
	return _Location;
}
PHY_Shapes PHYCollisionObj::getShape() const
{
	return _Shape;
}
int PHYCollisionObj::getIndex()
{
	return _thisIndex;
}
void PHYSphere::setRadius(double iRad)
{
	_Radius = iRad;
}
double PHYSphere::getRadius()
{
	return _Radius;
}

PHYCollisionObj & PHYCollisionObj::operator=(const PHYCollisionObj &rhs)
{
	PHYVector vect = rhs.getLocation();
	_Location.setVector(vect);
	_Shape = rhs.getShape();
	return *this;
}
int PHYCollisionObj::operator==(const PHYCollisionObj &rhs) const
{
	if(_thisIndex == rhs._thisIndex)
		return 1;
	return 0;
}
int PHYCollisionObj::operator<(const PHYCollisionObj &rhs) const
{
	if(_thisIndex < rhs._thisIndex)
		return 1;
	return 0;
}

//PHYCollisionObj* PHYCollisionObj::operator->()
//{
//	return this;
//}

PHYBox::PHYBox(osg::Geode *iGeode, double iX, double iY, double iZ, PHYVector &iOrigin)
:PHYCollisionObj(PHY_Box, iGeode, iOrigin)
{
	_X = iX; _Y = iY; _Z = iZ;
}
PHYConvex::PHYConvex(osg::Node *ipNode, char* iFName, PHYVector &iOrigin)
:PHYCollisionObj(PHY_Convex, ipNode, iOrigin)
{
	_filename = iFName;
}
char *PHYConvex::GetFileName()
{
	return _filename;
}
